import redis
import time

if __name__ == '__main__':
    cli = redis.StrictRedis(
        host="192.168.189.137",
        port=6379,
        db=4
    )
# 4 号 数据库准备就绪
    cli.flushdb()
# 有序集合 同样没有修改功能 但是有权重
# 增
    cli.zadd("zset1", 1, "a", 3, "c", 2, "b", 4, "d")
    cli.zadd("zset2", 1, "aa", 3, "cc", 2, "bb", 4, "dd")
# 查
    print(cli.zrange("zset1", 0, -1))   # 默认以权重升序
    print(cli.zrange("zset1", 0, -1, True))  # 以权重降序排列
# 根据 权重范围 进行 查询
    print(cli.zrangebyscore("zset1", 2, 4))
# 删
    cli.zrem("zset2", "aa")
    print(cli.zrange("zset2", 0, -1))
# 根据 权重范围 进行 删除
    cli.zremrangebyscore("zset2", 2, 3)
    print(cli.zrange("zset2", 0, -1))
# 查询 单个 值的 权重
    print(cli.zscore("zset1", "c"))


